package com.coderman.controller.business;

import com.coderman.business.service.IPayMentTypeService;
import com.coderman.business.service.IPayMentTypeService;
import com.coderman.common.annotation.ControllerEndpoint;
import com.coderman.common.error.SystemException;
import com.coderman.common.model.payMent.PayMentType;
import com.coderman.common.response.ResponseBean;
import com.coderman.common.vo.system.PageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 缴费项目管理
 *
 * @Author liwei
 * @Date 2023/1/8 14:11
 * @Version 1.0
 **/
@Api(tags = "系统模块-缴费项目相关接口")
@Controller
@RequestMapping("/payTpye")
public class PayMentTypeController {


    @Autowired
    private IPayMentTypeService payMentTypeService;

    /**
     * 缴费项目列表
     *
     * @return
     */
    @ApiOperation(value = "缴费项目列表", notes = "缴费项目列表,根据缴费项目名模糊查询")
    @GetMapping("/findPayMentTypeList")
    @ResponseBody
    public ResponseBean<PageVO<PayMentType>> findPayMentTypeList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                               @RequestParam(value = "pageSize") Integer pageSize,
                                                               PayMentType payMentType) {
        PageVO<PayMentType> PayMentTypesList = payMentTypeService.findPayMentTypeList(pageNum, pageSize, payMentType);
        return ResponseBean.success(PayMentTypesList);
    }

    /**
     * 所有缴费项目
     *
     * @return
     */
    @ApiOperation(value = "所有缴费项目")
    @GetMapping("/findAll")
    @ResponseBody
    public ResponseBean<List<PayMentType>> findAll() {
        List<PayMentType> payMentType = payMentTypeService.findAll();
        return ResponseBean.success(payMentType);
    }

//    /**
//     * 查找缴费项目主任
//     *
//     * @return
//     */
//    @ApiOperation(value = "缴费项目主任", notes = "查找缴费项目主任,排除掉已经禁用的用户")
//    @GetMapping("/findDeanList")
//    @ResponseBody
//    public ResponseBean<List<DeanVO>> findDeanList() {
//        List<DeanVO> managerList = PayMentTypeService.findDeanList();
//        return ResponseBean.success(managerList);
//    }

    /**
     * 添加缴费项目
     *
     * @return
     */
    @ControllerEndpoint(exceptionMessage = "添加缴费项目失败", operation = "添加缴费项目")
    @ApiOperation(value = "添加缴费项目")
    @PostMapping("/add")
    @ResponseBody
    public ResponseBean add(@RequestBody @Validated PayMentType payMentType) {
        payMentTypeService.add(payMentType);
        return ResponseBean.success();
    }

    /**
     * 编辑缴费项目
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "编辑缴费项目")
    @RequiresPermissions({"PayMentType:edit"})
    @GetMapping("/edit/{id}")
    @ResponseBody
    public ResponseBean edit(@PathVariable Integer id) throws SystemException {
        PayMentType payMentType = payMentTypeService.edit(id);
        return ResponseBean.success(payMentType);
    }

    /**
     * 更新缴费项目
     *
     * @return
     */
    @ControllerEndpoint(exceptionMessage = "更新缴费项目失败", operation = "更新缴费项目")
    @ApiOperation(value = "更新缴费项目")
    @RequiresPermissions({"PayMentType:update"})
    @PostMapping("/update")
    @ResponseBody
    public ResponseBean update(@RequestBody @Validated PayMentType payMentType) throws SystemException {
        payMentTypeService.update(payMentType);
        return ResponseBean.success();
    }

    /**
     * 删除缴费项目
     *
     * @param id
     * @return
     */
    @ControllerEndpoint(exceptionMessage = "删除缴费项目失败", operation = "删除缴费项目")
    @ApiOperation(value = "删除缴费项目")
    @RequiresPermissions({"payMentType:delete"})
    @DeleteMapping("/delete/{id}")
    @ResponseBody
    public ResponseBean delete(@PathVariable Integer id) throws SystemException {
        PayMentType payMentType = new PayMentType();
        payMentType.setPmtypeid(id);
        payMentType.setStatus("1");//禁用
        payMentTypeService.update(payMentType);
        return ResponseBean.success();
    }
}
